<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Transition</title>
  </head>

  <body>
    <canvas width="750" height="1000" id="canvas" style="width: 100%"></canvas>
    <script src="https://cdn.bootcdn.net/ajax/libs/pixi.js/4.8.7/pixi.min.js"></script>

    <script src="/dist/cdn/EVA.js"></script>
    <script src="/dist/cdn/EVA.rendererAdapter.js"></script>
    <script src="/dist/cdn/EVA.plugin.renderer.js"></script>
    <script src="/dist/cdn/EVA.plugin.renderer.img.js"></script>
    <script src="/dist/cdn/EVA.plugin.transition.js"></script>

    <script>
      const {Game, GameObject, resource, RESOURCE_TYPE} = EVA;
      const {RendererSystem} = EVA.plugin.renderer;
      const {Img, ImgSystem} = EVA.plugin.renderer.img;
      const {Transition, TransitionSystem} = EVA.plugin.transition;

      resource.addResource([
        {
          name: 'heart',
          type: RESOURCE_TYPE.IMAGE,
          src: {
            image: {
              type: 'png',
              url: '//gw.alicdn.com/bao/uploaded/TB1lVHuaET1gK0jSZFhXXaAtVXa-200-200.png',
            },
          },
          preload: false,
        },
      ]);

      const game = new Game({
        systems: [
          new RendererSystem({
            canvas: document.querySelector('#canvas'),
            width: 750,
            height: 1000,
          }),
          new ImgSystem(),
          new TransitionSystem(),
        ],
      });

      const image = new GameObject('image', {
        size: {width: 200, height: 200},
        origin: {x: 0, y: 0},
        position: {
          x: 0,
          y: 0,
        },
        anchor: {x: 0.5, y: 0.5},
      });
      const img = image.addComponent(
        new Img({
          resource: 'heart',
        }),
      );

      const animation = image.addComponent(new Transition());
      animation.group = {
        idle: [
          {
            name: 'scale.x',
            component: image.transform,
            values: [
              {
                time: 0,
                value: 1,
                tween: 'ease-out',
              },
              {
                time: 300,
                value: 1.2,
                tween: 'ease-in',
              },
              {
                time: 600,
                value: 1,
              },
            ],
          },
          {
            name: 'scale.y',
            component: image.transform,
            values: [
              {
                time: 0,
                value: 1,
                tween: 'ease-out',
              },
              {
                time: 300,
                value: 1.2,
                tween: 'ease-in',
              },
              {
                time: 600,
                value: 1,
              },
            ],
          },
        ],
        move: [
          {
            name: 'position.x',
            component: image.transform,
            values: [
              {
                time: 0,
                value: 1,
                tween: 'ease-out',
              },
              {
                time: 300,
                value: 300,
                tween: 'ease-in',
              },
            ],
          },
          {
            name: 'position.y',
            component: image.transform,
            values: [
              {
                time: 0,
                value: 1,
                tween: 'ease-in',
              },
              {
                time: 300,
                value: 300,
              },
            ],
          },
        ],
      };

      animation.play('move', 1);
      animation.on('finish', name => {
        name === 'move' && animation.play('idle', 5);
      });

      game.scene.addChild(image);
    </script>
  </body>
</html>
